package com.airy.apprepairequipment.controller;

import com.airy.apprepairequipment.common.util.UUID;
import com.airy.apprepairequipment.common.utils.PageUtils;
import com.airy.apprepairequipment.common.utils.R;
import com.airy.apprepairequipment.entity.RtJdloopgroupEntity;
import com.airy.apprepairequipment.service.RecJdloopgroupService;
import com.airy.apprepairequipment.service.RtJdloopgroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * ${comments}
 *
 * @author dingyakun
 * @email 821041490@qq.com
 * @date 2020-11-16 12:25:24
 */
@RestController
@RequestMapping("product/rtjdloopgroup")
public class RtJdloopgroupController {
    @Autowired
    private RtJdloopgroupService rtJdloopgroupService;
    @Autowired
    private RecJdloopgroupService recJdloopgroupService;


    public RtJdloopgroupEntity selectByFstrLoopgroupid(String fstrLoopgroupid) {
        return rtJdloopgroupService.selectByFstrLoopgroupid(fstrLoopgroupid);
    }

    /**
     * 测试查询所有信息
     *
     * @return
     */
    @RequestMapping("/select")
    public List<RtJdloopgroupEntity> select() {
        List<RtJdloopgroupEntity> list = rtJdloopgroupService.list();
        return list;
    }

    /**
     * 测试批量插入时提高插入效率：
     * 在数据库连接的url配置中 添加 rewriteBatchedStatements=true
     */
    @RequestMapping("/insertBatch")
    public R insertBatch(@RequestBody RtJdloopgroupEntity[] rtJdloopgroupEntities) throws IOException {

        List<RtJdloopgroupEntity> rtJdloopgroupEntityList = Arrays.asList(rtJdloopgroupEntities);
        for (int i = 0; i < rtJdloopgroupEntityList.size(); i++) {
            rtJdloopgroupEntityList.get(i).setFstrLoopgroupid(UUID.getUUID());
//            rtJdloopgroupEntityList.get(i).setFdtTime(new Date());
        }

        System.out.println("开始时间：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

        rtJdloopgroupService.saveBatch(rtJdloopgroupEntityList, 10000);

        System.out.println("结束时间：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

        return R.ok();
    }


    /**
     * 删除
     */
    @RequestMapping("/deleteByIds")
    public R deleteByIds() {
//        List<String> ids = new ArrayList<>();
//        for (int i = 1; i <= 2000; i++) {
//            ids.add(String.valueOf(i));
//        }
//        rtJdloopgroupService.removeByIds(ids);
        Map<String, Object> map = new HashMap<>();
        map.put("FINT_OCCUPY", 100);
        rtJdloopgroupService.removeByMap(map);
        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = rtJdloopgroupService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{fstrLoopgroupid}")
    public R info(@PathVariable("fstrLoopgroupid") String fstrLoopgroupid) {
        RtJdloopgroupEntity rtJdloopgroup = rtJdloopgroupService.getById(fstrLoopgroupid);

        return R.ok().put("rtJdloopgroup", rtJdloopgroup);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody RtJdloopgroupEntity rtJdloopgroup) {
        rtJdloopgroupService.save(rtJdloopgroup);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody RtJdloopgroupEntity rtJdloopgroup) {
        rtJdloopgroupService.updateById(rtJdloopgroup);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] fstrLoopgroupids) {
        rtJdloopgroupService.removeByIds(Arrays.asList(fstrLoopgroupids));

        return R.ok();
    }

    public void ceshi() {
        System.out.println("测试成功");
    }

    public void insertRT(RtJdloopgroupEntity rtentity) {
        rtJdloopgroupService.insertRT(rtentity);
    }

    public void insertWeiBoRT(RtJdloopgroupEntity rtJdloopgroupEntity) {
        rtJdloopgroupService.insertWeiBoRT(rtJdloopgroupEntity);
    }
}
